const cloud = require('wx-server-sdk');
//修改申请者状态
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});

const db=cloud.database();

exports.main = async (event, context) => {
  const {account,modify,remark}=event.data;
  try{
    const repeat=await db.collection("student").where(
      {
        account:account
      }
    ).get();
    if(repeat.data.length==1){
      switch(modify){
        case 0://修改审核状态
          try{
            const up=await db.collection("student").where({
             account:account
             }).update({
                data:{
                check_status:repeat.data[0].check_status+1,
              }
              })
              return {success:true,message:"修改成功"}
            }catch(error){
                console.error(error);
                return{success:false,message:"0"+error}
             }
        break;
        case 1://打回申请
          try{
            const up=await db.collection("student").where({
             account:account
             }).update({
                data:{
                remark:remark,
                application_status:0
              }
              })
              return {success:true,message:"修改成功"}
            }catch(error){
                console.error(error);
                return{success:false,message:"0"+error}
             }
          break;
      }
    }
    else{
      return {success:false,message:"修改失败"}
    }
  }catch(error){
    return{success:false,message:"1"}
  }
};